<?php
require_once($server->my_site[0]->path.$server->my_site[0]->folder."distributor_manage.php");

$distributor->id or exit("Área reservada a distribuidores");

$orders_ids=array();
if (isset($_GET['order_id'])) array_push($orders_ids, $_GET['order_id']);
else $orders_ids=explode(",",$_COOKIE['selectedOrders']);

$orders=array();
foreach ($distributor->unprocessed_orders as $order) {
	foreach ($orders_ids as $order_id) {
		if ($order->id==$order_id) array_push($orders, $order);
	}
}
foreach ($distributor->processed_orders as $order) {
	foreach ($orders_ids as $order_id) {
		if ($order->id==$order_id) array_push($orders, $order);
	}
}

?>

<?php
#Vamos con las acciones
foreach ($orders as $order) {
?>
<div style="margin: 1em 0;">
<?php
  #It checks that the order status is below 2, so 1=unprocessed
  if ($order->status>1) {
	echo "Error: La orden ".$order->id." ha sido ya procesada anteriormente";
	continue;
  }

#Change status to 2: processed
$order->status='2';
$order->db_update_status();

?>
<p>Estado cambiado a <?php echo $order->status; ?>.</p>
</div>
<?php
}
?>
<script language="javascript">
	reload("#orders","?section=orders");
</script>
